/**
 * 自定义分页功能
 * @param $this 标签
 * @param $page 当前页
 * @param $size 每页条数
 * @param $total 数据总数
 * @param $url 可点击的链接
 */
var paging = function($this, $page, $size, $total, $url){
	var pages = $total/$size;
	if(pages != parseInt(pages)){
		pages = parseInt(pages) + 1;
	}
	if($url == null){
		$url = '';
	}
	
	var inner = "<ul>";
	var a_put = function(nowpage, span, clickurl, thepage, pages){
		var apre = ">";
		var alast = "";
		if(span == nowpage && nowpage == thepage){
			apre = " class='currentpage'>";
		}
		if(thepage != nowpage && nowpage != pages){
			switch(span){
			case '首页':
				nowpage = 1;
				break;
			case '上一页':
				nowpage = (nowpage-1) < 1 ? pages : --nowpage; 
				break;
			case '下一页':
				nowpage = (nowpage+1) > pages ? pages : ++nowpage; 
				break;
			case '末页':
				nowpage = pages;
				break;
			default:
				nowpage = thepage;
				break;
			}
			apre += "<a href='" + clickurl + nowpage + "'>";
			alast = "</a>";
		}
		return "<li><span" + apre + span + alast + "</span></li>";
	};
	
	inner += a_put($page, "首页", $url, 1) + a_put($page, "上一页", $url, 1);
	var preomit = true;
	var nextomit = true;
	for(var i = 0;i < pages; i++){
		if(i >= $page-3 && i < $page+2 || i < 2){
			inner += a_put($page, i+1, $url, i+1);
		}else if(i < $page-3){
			if(preomit){
				inner += a_put(1, '...', null, 1);
				preomit = false;
			}
		}else if(i > $page+1){
			if(nextomit){
				inner += a_put(1, '...', null, 1);
				nextomit = false;
			}
		}
	}
	inner += a_put($page, "下一页", $url, null, pages) + a_put($page, "末页", $url, null, pages);
	inner += "</ul>";
	if($total != 0){
		$this.html( inner );
	};
};